package com.example.javabasic.thread.classtwo.activeobject.demo1;

/**
 * 执行异步方法的桥梁
 */
public class SchedulerThread extends Thread {

    private final ActivationQueue activationQueue;

    /**
     * 构造一个队列
     * @param activationQueue
     */
    public SchedulerThread(ActivationQueue activationQueue) {
        this.activationQueue = activationQueue;
    }

    /**
     * 将request 放入 activationQueue中  等待消费
     * @param request
     */
    public void invoke(MethodRequest request){
        this.activationQueue.put(request);
    }


    /**
     * 线程运行  从queue中取出request  进行消费
     */
    @Override
    public void run() {
        while(true){
            MethodRequest take = activationQueue.take();
            take.execute();
        }
    }
}
